package com.example.healthmanagement.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.healthmanagement.entity.CookBook;
import com.example.healthmanagement.pojo.Sportinfo;
import com.example.healthmanagement.service.CookBookService;
import com.example.healthmanagement.service.SportinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/cookbook")
public class CookBookController {

    @Autowired
    CookBookService cookBookService;

    @GetMapping("")
    public List<CookBook> getAllCookBook(String cookBookName) {
        return cookBookService.findAll(cookBookName);
    }

    @PostMapping("")
    public boolean saveCookBook(@RequestBody CookBook cookBook) {
        cookBook.setCreatedAt(LocalDateTime.now());
        cookBook.setUpdatedAt(LocalDateTime.now());
        cookBook.setDeleted(false);
        return cookBookService.addCookBook(cookBook);
    }
    @PutMapping("")
    public boolean updateCookBook(@RequestBody CookBook cookBook) {
        return cookBookService.updateCookBook(cookBook);
    }

    @DeleteMapping  ("/{id}")
    public boolean deleteCookBook(@PathVariable("id") int id) {
        CookBook cookBook = cookBookService.findCookBookById(id);
        cookBook.setDeleted(true);
        return cookBookService.updateCookBook(cookBook);
    }
}
